<?php 
$dirname = $_POST['webname']?$_POST['webname']:$_GET['dirname'];
if($_GET['jmfile']){
	$dirname = substr($_GET['jmfile'], 0, strrpos($_GET['jmfile'], "/"));
}
if($dirname == ""){
	$dirname = ".";
}
if($_GET['updir'] == "updir"){
	if($dirname != "."){
		$dirname = substr($dirname, 0, strrpos($dirname, "/"));
	}
}
?>
<html>
	<head>
		<meta charset="utf-8">
		<title>dir:<?php echo $dirname;?></title>
	</head>
	<body>
		<form action="jjMi_select.php" method="post">
			<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path：
			<input style="width: 80%;" type="text" name="webname" id="webname" value="<?php echo $dirname;?>" /> <br />
			<input style="margin-left: 100px;margin-top: 12px;" type="submit" value="打开"/>
		</form>
		<a href="jjMi_select.php?updir=updir&dirname=<?php echo $dirname;?>">返回上级目录</a>
		<br />
	</body>
</html>
<?php
function getRealSize($size) {
	$kb = 1024;// Kilobyte  
	$mb = 1024 * $kb; // Megabyte  
	$gb = 1024 * $mb; // Gigabyte  
	$tb = 1024 * $gb; // Terabyte  
	if($size < $kb){
		return $size." B";  
	}else if($size < $mb)  {
		return round($size/$kb,2)." KB";  
	}else if($size < $gb)  {
		return round($size/$mb,2)." MB"; 
	}else if($size < $tb){  
	    return round($size/$gb,2)." GB";  
	}else{
		return round($size/$tb,2)." TB";  
	} 
}

function getColor($timeInt){
	$cj_time=time() - $timeInt;
	if($cj_time < 86400){
		return "red";
	}elseif($cj_time < 259200){
		return "blue";
	}elseif($cj_time < 604800){
		return "green";
	}else{
		return "black";
	}
}

function jiaMi($filename){
	$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	$T_k1 = str_shuffle($str); 
	$T_k2 = str_shuffle($str); 
	$vstr = file_get_contents($filename);
	$v1 = base64_encode($vstr);
	$c = strtr($v1, $T_k1, $T_k2);
	$c = $T_k1.$T_k2.$c;
	
	$q1 = "O00O0O";
	$q2 = "O0O000";
	$q3 = "O0OO00";
	$q4 = "OO0O00";
	$q5 = "OO0000";
	$q6 = "O00OO0";
	$s = '$'.$q6.'=urldecode("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A");$'.$q1.'=$'.$q6.'{3}.$'.$q6.'{6}.$'.$q6.'{33}.$'.$q6.'{30};$'.$q3.'=$'.$q6.'{33}.$'.$q6.'{10}.$'.$q6.'{24}.$'.$q6.'{10}.$'.$q6.'{24};$'.$q4.'=$'.$q3.'{0}.$'.$q6.'{18}.$'.$q6.'{3}.$'.$q3.'{0}.$'.$q3.'{1}.$'.$q6.'{24};$'.$q5.'=$'.$q6.'{7}.$'.$q6.'{13};$'.$q1.'.=$'.$q6.'{22}.$'.$q6.'{36}.$'.$q6.'{29}.$'.$q6.'{26}.$'.$q6.'{30}.$'.$q6.'{32}.$'.$q6.'{35}.$'.$q6.'{26}.$'.$q6.'{30};eval($'.$q1.'("'.base64_encode('$'.$q2.'="'.$c.'";eval(\'?>\'.$'.$q1.'($'.$q3.'($'.$q4.'($'.$q2.',$'.$q5.'*2),$'.$q4.'($'.$q2.',$'.$q5.',$'.$q5.'),$'.$q4.'($'.$q2.',0,$'.$q5.'))));').'"));'; 
	$s = '<?php '."\n".$s."\n".'?>';
	$fpp1 = fopen($filename, 'w');
	$back = fwrite($fpp1, $s);
	if($back){
		echo "文件： ".$filename." 加密成功！ 加密写入 ".$back." 字节。<br>";
	}else{
		echo "加密文件 ".$filename." 时出现写入出错！<br>";
	}
}

function jieMi($filename){
	$f_content = file_get_contents($filename);
	preg_match('/eval\(\$O00O0O\(/', $f_content, $matches, PREG_OFFSET_CAPTURE);
	preg_match('/"\)\);/', $f_content, $matches2, PREG_OFFSET_CAPTURE);
	if($matches && $matches2){
		$len = strlen($f_content);
		$start = $matches[0][1];
		$length = $matches2[0][1] - $len;
		$str = substr($f_content, $start + 14, $length);
		$str_de = base64_decode($str);
		$q2 = substr($str_de, 9, -118);
		$a = substr($q2,52*2);
		$b = substr($q2,52,52);
		$c = substr($q2,0,52);
		$qq = base64_decode(strtr($a ,$b, $c));
		$fpp1 = fopen($filename, 'w');
		$back = fwrite($fpp1, $qq);
		if($back){
			echo "文件： ".$filename." 解密成功！ 解密写入 ".$back." 字节。<br>";
		}else{
			echo "解密文件 ".$filename." 时出现写入出错！<br>";
		}
	}else{
		echo "文件 ".$filename." 是明文代码。<br>";
	}
}

if($_GET['jiami'] == "jiami"){
	echo "加密：";
	jiaMi($_GET['jmfile']);
}

if($_GET['jiemi'] == "jiemi"){
	echo "解密：";
	jieMi($_GET['jmfile']);
}
echo "<hr>";

function getdir($path){
	$arr=scandir($path);
	foreach($arr as $v){
		if($v!="."&&$v!=".."){
			$filePath=$path."/".$v;
			$cTimeInt=filectime($filePath);
			$mTimeInt=filemtime($filePath);
			$cTime=date("Y-m-d H:i:s",$cTimeInt);
			$mTime=date("Y-m-d H:i:s",$mTimeInt);
			$cColor=getColor($cTimeInt);
			$mColor=getColor($mTimeInt);
			if(is_dir($path."/".$v)){
				echo "目录：".$filePath." <span style='color: sandybrown;'>-->文件夹</span>
				<a style='border: 3px solid orange;' href='jjMi_select.php?dirname=".$filePath."'>进入文件夹</a> &nbsp; ";
				echo "<br><br>";
			}else{
				$ext = substr($v, (strrpos($v, ".") + 1));
				$getSize=getRealSize(filesize($filePath));
				
				$f_content = file_get_contents($filePath);
				preg_match('/eval\(\$O00O0O\(/', $f_content, $matches, PREG_OFFSET_CAPTURE);
				preg_match('/"\)\);/', $f_content, $matches2, PREG_OFFSET_CAPTURE);
				if($matches && $matches2){
					$is_mi = "密";
					$c_rb = "red";
				}else{
					$is_mi = "明";
					$c_rb = "black";
				}
				
				if ($ext == 'html') {
					echo "文件：<span style='color: ".$c_rb.";'> ".$filePath." </span> <span style='color: greenyellow;'>--> HTML文件</span>"."
					<a style='border: 2px solid red;' href='jjMi_select.php?jiami=jiami&jmfile=".$filePath."'>jiaMi</a>&nbsp;&nbsp;".$is_mi."&nbsp;&nbsp;
					<a style='border: 2px solid green;' href='jjMi_select.php?jiemi=jiemi&jmfile=".$filePath."'>jieMi</a> &nbsp; ".$getSize." &nbsp; 
					<span style='color: plum;'>Ctime : </span><span style='color: ".$cColor.";'>".$cTime."</span> &nbsp; 
					<span style='color: pink;'>Mtime : </span><span style='color: ".$mColor.";'>".$mTime."</span>";
				} elseif ($ext == 'php') {
					echo "文件：<span style='color: ".$c_rb.";'> ".$filePath." </span> <span style='color: blue;'>--> PHP文件</span>"."
					<a style='border: 2px solid red;' href='jjMi_select.php?jiami=jiami&jmfile=".$filePath."'>jiaMi</a>&nbsp;&nbsp;".$is_mi."&nbsp;&nbsp;
					<a style='border: 2px solid green;' href='jjMi_select.php?jiemi=jiemi&jmfile=".$filePath."'>jieMi</a> &nbsp; ".$getSize." &nbsp; 
					<span style='color: plum;'>Ctime : </span><span style='color: ".$cColor.";'>".$cTime."</span> &nbsp; 
					<span style='color: pink;'>Mtime : </span><span style='color: ".$mColor.";'>".$mTime."</span>";
				} elseif ($ext == 'js') {
					echo "文件：<span style='color: ".$c_rb.";'> ".$filePath." </span> <span style='color: blueviolet;'>--> JS文件</span>"."
					<a style='border: 2px solid red;' href='jjMi_select.php?jiami=jiami&jmfile=".$filePath."'>jiaMi</a>&nbsp;&nbsp;".$is_mi."&nbsp;&nbsp;
					<a style='border: 2px solid green;' href='jjMi_select.php?jiemi=jiemi&jmfile=".$filePath."'>jieMi</a> &nbsp; ".$getSize." &nbsp; 
					<span style='color: plum;'>Ctime : </span><span style='color: ".$cColor.";'>".$cTime."</span> &nbsp; 
					<span style='color: pink;'>Mtime : </span><span style='color: ".$mColor.";'>".$mTime."</span>";
				} elseif ($ext == 'css') {
					echo "文件：<span style='color: ".$c_rb.";'> ".$filePath." </span> <span style='color: coral;'>--> css文件</span>"."
					<a style='border: 2px solid red;' href='jjMi_select.php?jiami=jiami&jmfile=".$filePath."'>jiaMi</a>&nbsp;&nbsp;".$is_mi."&nbsp;&nbsp;
					<a style='border: 2px solid green;' href='jjMi_select.php?jiemi=jiemi&jmfile=".$filePath."'>jieMi</a> &nbsp; ".$getSize." &nbsp; 
					<span style='color: plum;'>Ctime : </span><span style='color: ".$cColor.";'>".$cTime."</span> &nbsp; 
					<span style='color: pink;'>Mtime : </span><span style='color: ".$mColor.";'>".$mTime."</span>";
				} elseif ($ext == 'png') {
					echo "文件：<span style='color: ".$c_rb.";'> ".$filePath." </span> <span style='color: #00BFFF;'>--> png图片</span>"."
					<a style='border: 2px solid red;' href='jjMi_select.php?jiami=jiami&jmfile=".$filePath."'>jiaMi</a>&nbsp;&nbsp;".$is_mi."&nbsp;&nbsp;
					<a style='border: 2px solid green;' href='jjMi_select.php?jiemi=jiemi&jmfile=".$filePath."'>jieMi</a> &nbsp; ".$getSize." &nbsp; 
					<span style='color: plum;'>Ctime : </span><span style='color: ".$cColor.";'>".$cTime."</span> &nbsp; 
					<span style='color: pink;'>Mtime : </span><span style='color: ".$mColor.";'>".$mTime."</span>";
				} elseif ($ext == 'jpg') { 
					echo "文件：<span style='color: ".$c_rb.";'> ".$filePath." </span> <span style='color: #0066B3;'>--> JPG图片</span>"."
					<a style='border: 2px solid red;' href='jjMi_select.php?jiami=jiami&jmfile=".$filePath."'>jiaMi</a>&nbsp;&nbsp;".$is_mi."&nbsp;&nbsp;
					<a style='border: 2px solid green;' href='jjMi_select.php?jiemi=jiemi&jmfile=".$filePath."'>jieMi</a> &nbsp; ".$getSize." &nbsp; 
					<span style='color: plum;'>Ctime : </span><span style='color: ".$cColor.";'>".$cTime."</span> &nbsp; 
					<span style='color: pink;'>Mtime : </span><span style='color: ".$mColor.";'>".$mTime."</span>";
				} elseif ($ext == 'txt') {
					echo "文件：<span style='color: ".$c_rb.";'> ".$filePath." </span> <span style='color: lightslategrey;'>--> TXT文件</span>"."
					<a style='border: 2px solid red;' href='jjMi_select.php?jiami=jiami&jmfile=".$filePath."'>jiaMi</a>&nbsp;&nbsp;".$is_mi."&nbsp;&nbsp;
					<a style='border: 2px solid green;' href='jjMi_select.php?jiemi=jiemi&jmfile=".$filePath."'>jieMi</a> &nbsp; ".$getSize." &nbsp; 
					<span style='color: plum;'>Ctime : </span><span style='color: ".$cColor.";'>".$cTime."</span> &nbsp; 
					<span style='color: pink;'>Mtime : </span><span style='color: ".$mColor.";'>".$mTime."</span>";
				} else {
					echo "文件：<span style='color: ".$c_rb.";'> ".$filePath." </span> <span style='color: red;'>--> 其他文件</span>"."
					<a style='border: 2px solid red;' href='jjMi_select.php?jiami=jiami&jmfile=".$filePath."'>jiaMi</a>&nbsp;&nbsp;".$is_mi."&nbsp;&nbsp;
					<a style='border: 2px solid green;' href='jjMi_select.php?jiemi=jiemi&jmfile=".$filePath."'>jieMi</a> &nbsp; ".$getSize." &nbsp; 
					<span style='color: plum;'>Ctime : </span><span style='color: ".$cColor.";'>".$cTime."</span> &nbsp; 
					<span style='color: pink;'>Mtime : </span><span style='color: ".$mColor.";'>".$mTime."</span>";
				}
				echo "<br><br>";
			}
		}
	}		
}
getdir($dirname);
?>
